package com.example.rabbitmqdemo.hellorabbitmq.wrokqueues;

import cn.hutool.core.util.StrUtil;
import com.example.rabbitmqdemo.hellorabbitmq.CommonUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.concurrent.TimeoutException;

public class ProducerWorkQueues {
    static final String WORK_QUEUES = "work_queues";
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        ConnectionFactory factory = CommonUtil.getFactory();
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(WORK_QUEUES, true, false, false, null);

        for (int i = 0; i < 1000; i++) {
            String body = StrUtil.format("-- {} work queues {}", i, LocalDateTime.now());
            channel.basicPublish("", WORK_QUEUES, null, body.getBytes(StandardCharsets.UTF_8));
            Thread.sleep(100);
        }


    }
}
